package edu.cmu.ece.ds.droidchat.model;

import java.io.Serializable;

import android.graphics.drawable.Drawable;
import edu.cmu.ece.ds.droidchat.util.Toolbox;

/**
 * This class contains the whole user info. More than those displayed in the
 * nearby user list. The boolean isNeighbor tells whether the user should or
 * should not be displayed as a neighbor
 */
public class UserInfo implements Serializable {

    public static enum Availability {
        AVAILABLE, /*IDLE, */BUSY/*, OFFLINE*/
    }

    private static final long serialVersionUID = 4175397163410019552L;
    private Availability avail;
    private String nickName;
    private String statusMessage;
    private String username;
    private Drawable profilePicture;
    private MessageBackgroundColor mMessageBackgroundColor = MessageBackgroundColor.AQUA;

    private String userIP; // the ip of this user
    private int round; // this user is in my neighbor list because
                        // the server said he was my neighbor in response to my
                        // location
                        // in round 'round'

    private int loginSessionId; // only useful for myInfo
    private int chatSessionNum = 0; // only useful for myInfo
    private boolean isNeighbor = false;

    public UserInfo(String id, String name) {
        this(id, name, null, Availability.AVAILABLE,
                MessageBackgroundColor.AQUA);
    }

    public UserInfo(String username, String nickName, Drawable profilePhoto,
            Availability avail, MessageBackgroundColor messageBackgroundColor) {
        this.username = username;
        this.nickName = Toolbox.convertUnicodeEscape(nickName);
        this.profilePicture = profilePhoto;
        this.avail = avail;
        this.mMessageBackgroundColor = messageBackgroundColor;
    }

    public Availability getAvailability() {
        return avail;
    }

    public void setAvailability(Availability availability) {
        this.avail = availability;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
    }

    public String getUserIP() {
        return userIP;
    }

    public void setUserIP(String userIp) {
        this.userIP = userIp;
    }

    public String getProfilePictureURLString() {
        return StringConstants.URL_PREFIX_FACEBOOK_GRAPH + username
                + StringConstants.URL_POSTFIX_FACEBOOK_PICTURE;
    }

    public Drawable getProfilePicture() {
        return profilePicture;
    }

    public void setProfilePicture(Drawable profilePicture) {
        this.profilePicture = profilePicture;
    }

    public MessageBackgroundColor getMessageBackgroundColor() {
        return mMessageBackgroundColor;
    }

    public void setMessageBackgroundColor(
            MessageBackgroundColor mMessageBackgroundColor) {
        this.mMessageBackgroundColor = mMessageBackgroundColor;
    }

    public int getLoginSessionId() {
        return loginSessionId;
    }

    public void setLoginSessionId(int loginSessionId) {
        this.loginSessionId = loginSessionId;
    }

    public int getChatSessionNum() {
        return ++chatSessionNum;
    }

    @Override
    public String toString() {
        return "UserInfo[username=" + username + ",nickName=" + nickName + "]";
    }

    public boolean isANeighbor() {
        return isNeighbor;
    }

    public void setNeighbor(boolean isANeighbor) {
        this.isNeighbor = isANeighbor;
    }

}
